]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
ui: Allow moving menu items to a certain position
authorBenjamin Berg <bberg@redhat.com>
Mon, 13 Feb 2017 15:02:02 +0000 (16:02 +0100)
committerBenjamin Berg <bberg@redhat.com>
Wed, 15 Feb 2017 21:49:04 +0000 (22:49 +0100)
This function is a helper to simplify keeping menu items ordered when
their order is updated on the fly (e.g. network connections being
renamed).

https://bugzilla.gnome.org/show_bug.cgi?id=778686

js/ui/popupMenu.js

index 52a58d6b85c912e7fe7695db1e076da937b51b9f..011a95ac051b8abe86cfc1ecd30994450532b337 100644 (file)
@@ -605,6 +605,24 @@ const PopupMenuBase = new Lang.Class({
         menuItem.actor.show();
     },
 
+    moveMenuItem: function(menuItem, position) {
+        let items = this._getMenuItems();
+        let i = 0;
+
+        while (i < items.length && position > 0) {
+                if (items[i] != menuItem)
+                        position--;
+                i++;
+        }
+
+        if (i < items.length) {
+                if (items[i] != menuItem)
+                        this.box.set_child_below_sibling(menuItem.actor, items[i].actor);
+        } else {
+                this.box.set_child_above_sibling(menuItem.actor, null);
+        }
+    },
+
     addMenuItem: function(menuItem, position) {
         let before_item = null;
         if (position == undefined) {